package org.demo.szml.loggingservice.service.impl;

import org.demo.szml.eventtype.event.logging.LoggingEvent;
import org.demo.szml.loggingservice.repository.ILoggingRepository;
import org.demo.szml.loggingservice.repository.po.OperationLogsPO;
import org.demo.szml.loggingservice.service.ILoggingService;
import org.springframework.stereotype.Service;

/**
 * @description: 日志服务实现类
 * @date: 2025/6/16 15:01
 * @version: 1.0
 */
@Service
public class LoggingServiceImpl implements ILoggingService {

    private final ILoggingRepository loggingRepository;

    public LoggingServiceImpl(ILoggingRepository loggingRepository){
        this.loggingRepository = loggingRepository;
    }

    @Override
    public void saveOperationLog(LoggingEvent.LoggingEventInfo data) {
        OperationLogsPO po = new OperationLogsPO();
        po.setUserId(data.getUserId());
        po.setAction(data.getAction());
        po.setIp(data.getIp());
        po.setDetail(data.getDetail());
        po.setLogId(data.getLogId());
        po.setOperationStatus(data.getStatusCode());
        loggingRepository.saveOperationLog(po);
    }
}
